package cn.laixueit.resource.feign.controller;

import cn.laixueit.po.TbBookChapter;
import cn.laixueit.po.TbBookChapterContent;
import cn.laixueit.resource.BookInterface;
import cn.laixueit.resource.feign.client.BookFeign;
import cn.laixueit.resource.feign.result.R;
import cn.laixueit.vo.BookVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 前端前台访问得
 * @author duxiang
 * @date 2024/2/23 16:04
 */
@RestController
@RequestMapping("/home")
public class HomeWebController implements BookInterface {
    @Resource
    private BookFeign bookFeign;

  /*  @GetMapping("/blog/findBookCategoryNames")
    public R findBookCategoryNames(){
        Object list = bookFeign.findBookCategoryNames();
        return R.ok().put("rows",list);
    }

    @GetMapping("/blog/findBookDate")
    public R findBookDate(){
        Object map = bookFeign.findBookDate();
        return R.ok().put("T",map);
    }*/

    @GetMapping("/blog/randHotBook")
    public R randHotBook(){
        return R.data(bookFeign.randHotBook());
    }

    @Override
    public R list(){
        Object list = bookFeign.list();
        return R.ok().put("rows",list);
    }

    @Override
    public R page(Integer page, Integer size, BookVo bookVo) {
        Object o = bookFeign.page(page, size, bookVo);
        return R.ok().put("T",o);
    }

    @Override
    public R save(BookVo bookVo) {
        Object save = bookFeign.save(bookVo);
        return R.ok().put("T",save);
    }

    @Override
    public R remove(String id,Boolean isDelete) {
        return R.ok().put("T",bookFeign.remove(id,isDelete));
    }

    @Override
    public R findById(String id) {
        return R.ok().put("T",bookFeign.findById(id)) ;
    }

    @Override
    public R findBookAndChapters(String id) {
        return R.ok().put("T",bookFeign.findBookAndChapters(id)) ;
    }

    @Override
    public R saveChapter(TbBookChapter chapter) {
        return R.ok().put("T",bookFeign.saveChapter(chapter)) ;
    }

    @Override
    public R listChapter(String bookId) {
        return R.ok().put("T", bookFeign.listChapter(bookId));
    }

    @Override
    public R removeChapter(String chapterId) {
        Object chapter = bookFeign.removeChapter(chapterId);
        return R.ok().put("T",chapter);
    }

    @Override
    public R findChapterContent(String chapterId) {
        return R.ok().put("T",bookFeign.findChapterContent(chapterId));
    }

    @Override
    public R saveChapterContent(TbBookChapterContent chapterContent) {
        return R.ok().put("T",bookFeign.saveChapterContent(chapterContent));
    }

    @Override
    public R findChapters(String bookId) {
        return R.ok().put("T",bookFeign.findChapters(bookId));
    }
}
